import Mock from 'mockjs'
// 6、正确使用mock模拟数据

const data = Mock.mock({
  'list|20-30': [{
    title: '@ctitle(4,10)',
    news: ['新华网', '央视网', ''],
    datetime: '@datetime',
  }],
  'tabs|5': [{
    'title': '@ctitle(2)',
    'id': '@id',
    'children|5': [{
      'titles|5': ['@ctitle(2)'],
      'id': '@id',
      'sel|5-10': ['@ctitle(2,4)']
    }]
  }]
})
// 加工一下图片
data.list.forEach(v => {
  const num = Mock.mock('@integer(1,3)')
  if (num === 1) {
    // 不需要添加图片
  } else if (num === 2) {
    // 添加字段 url   一张
    v.url = Mock.mock('@image(100x100, @color)')
  } else {
    // 添加字段 urls   三张
    v.urls = Mock.mock(['@image(100x100, @color)', '@image(100x100, @color)', '@image(100x100, @color)'])
  }
})

Mock.mock('/api/list', () => ({ code: 200, data: data.list }))
Mock.mock('/api/tabs', () => ({ code: 200, data: data.tabs }))